<template>
  <a-card :bordered="false">
    <s-table
      :alert="alert"
      :columns="columns"
      :data="loadData"
      :rowKey="record => record.id"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      bordered
      ref="table"
    >
      <span slot="action" slot-scope="record">
        <span v-action="'sys:dict:update'">
          <a @click="edit(record)">修改</a>
          <a-divider type="vertical"/>
        </span>
        <span>
          <a @click="showDictItem(record)" href="javascript:">字典配置</a>
          <a-divider type="vertical"/>
        </span>
        <span v-action="'sys:dict:del'">
          <a-popconfirm @confirm="del(record)" cancelText="否" okText="是" title="是否删除字典">
            <a-icon slot="icon" style="color: red" type="question-circle-o"/>
            <a href="javascript:" style="color: red">删除</a>
          </a-popconfirm>
        </span>
      </span>
    </s-table>
  </a-card>
</template>

<script>
import { delObj, fetchList } from '@api/sys/dict'
import { TableMixin } from '@/mixins/TableMixin'

export default {
  name: 'Dict',
  mixins: [TableMixin],
  data () {
    return {
      columns: [
        {
          title: '序号',
          width: '80px',
          align: 'center',
          customRender: (text, record, index) => {
            return (
              <div>
                {index + 1}
              </div>
            )
          }
        },
        {
          title: '字典名称',
          width: '10%',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '字典类型',
          width: '10%',
          align: 'center',
          dataIndex: 'type'
        },
        {
          title: '描述',
          dataIndex: 'remark'
        },
        {
          title: '操作',
          width: '180px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      queryParam: {
        name: '',
        type: ''
      },
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    edit (record) {
      this.$refs.dictAddOrUpdate.init(record.id, 'edit')
    },
    del (record) {
      delObj(record.id).then(_ => {
        this.$message.info('删除成功')
        this.queryPage()
      })
    }
  }
}
</script>

<style scoped>

</style>
